package com.lej.core.widget.transformPage

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlin.math.abs

/**
 * viewpager缩放切换动画
 * @param minScale 缩放比例
 */
class ZoomOutPageTransformer(private val minScale: Float = 0.85f) : ViewPager2.PageTransformer {
    override fun transformPage(page: View, position: Float) {
        if (position <= 1) {
            val scaleFactor = minScale + (1 - abs(position)) * (1 - minScale)
            page.scaleX = scaleFactor
            if (position > 0) {
                page.translationX = -scaleFactor * 2
            } else if (position < 0) {
                page.translationX = scaleFactor * 2
            }
            page.scaleY = scaleFactor
        } else {
            page.scaleX = minScale
            page.scaleY = minScale
        }
    }
}